package stuman.entity;

import java.io.Serializable;
import java.util.ArrayList;

public class Section implements Serializable{
	

	private static final long serialVersionUID = 1L;

	private String name;
	private double weight, earned, max;
	private ArrayList<Grade> grades = new ArrayList<Grade>();
	
	public Section(String n){
		name = n;
	}
	
	public String getName(){
		return name;
	}
	
	public void setWeight(double d){
		weight = d;
	}
	
	public void addGrade(Grade g){
		grades.add(g);
	}
	
	public void deleteGrade(Grade g)
	{	
		grades.remove(g);
	}
	
	public ArrayList<Grade> getGrades(){
		return grades;
	}
	
	public double getAverage(){
		earned = 0;
		max = 0;
		for (int i=0;i<grades.size();i++){
			earned = earned + grades.get(i).getActualScore();
			max = max + grades.get(i).getActualScore();
		}
		return earned/max;
	}
	
	public double getWeightedAverage(){
		if (weight > 0 && weight <= 100){
			return getAverage()*(weight/100);
		}
		else return 0;
		
	}
	
	
	

}
